package com.yoomiito.app.adapter.my

import android.graphics.Color
import android.text.TextUtils
import android.view.View
import android.widget.ImageView
import android.widget.TextView

import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.R
import com.yoomiito.app.model.my.MyMoneyDetailInfo
import com.yoomiito.app.utils.ImageLoader
import com.yoomiito.app.utils.ResUtil
import com.yoomiito.app.utils.SpannableUtils

class MyMoneyDetailAdapter(data: List<MyMoneyDetailInfo.DataBean>?) :
    BaseQuickAdapter<MyMoneyDetailInfo.DataBean, BaseViewHolder>(
        R.layout.item_my_money_detail,
        data
    ) {
    private var show: Boolean = false
    override fun convert(helper: BaseViewHolder, item: MyMoneyDetailInfo.DataBean) {
        helper.setText(R.id.tv_time, item.ctime)
        helper.setText(R.id.tv_content, item.bizTypeStr)
        val iv = helper.getView<ImageView>(R.id.agent_flag)
        when {
            TextUtils.isEmpty(item.image_url) -> iv.visibility = View.GONE
            else -> {
                iv.visibility = View.VISIBLE
                ImageLoader.getInstance().into(iv.context, item.image_url, iv)
            }
        }
        helper.setVisible(R.id.tv_detail, item.show == 1)
        helper.setText(R.id.tv_subtitle, item.accountTypeDesDetail)
        val moneyTv = helper.getView<TextView>(R.id.tv_money)
        moneyTv.setTextColor(
            ResUtil.getColor(if (item.money.contains("-")) R.color.color_balk_333333 else R.color.color_4AC142)
        )
        moneyTv.text = SpannableUtils.handlePrice(item.money)
        if (item.isShow) {
            helper.setVisible(R.id.item_order, true)
            helper.setText(R.id.item_goods_order_id, "订单：" + item.orderId)
            val goodsPicIv = helper.getView<ImageView>(R.id.item_goods_order_pic)
            ImageLoader.getInstance()
                .into(goodsPicIv.context, item.image, goodsPicIv, R.drawable.goods_default)
            val goodsTitleTv = helper.getView<TextView>(R.id.item_goods_order_title)
            goodsTitleTv.text = item.nickname
            val mobile = helper.getView<TextView>(R.id.item_mobile)
            mobile.text = item.ctime
            helper.setText(R.id.item_goods_order_status, item.statusStr)
            helper.setText(R.id.item_goods_order_date, item.ctime)
            helper.setText(R.id.item_goods_order_price, "¥" + item.money.replace("-","").replace("+",""));

            if (item.status == 1) {
                helper.setTextColor(R.id.item_goods_order_status, Color.parseColor("#333333"))
            } else {
                helper.setTextColor(R.id.item_goods_order_status, Color.parseColor("#FC873A"))
            }
        } else {
            helper.setGone(R.id.item_order, false)
        }
    }

    public fun setShow(show: Boolean){
        this.show = show
        notifyDataSetChanged()
    }

}
